const KoaRouter = require("@koa/router");
const { verifyAuth } = require("../middleware/authority.middleware");
const {
  releaseArticle,
  saveArticle,
  cancelSaveArticle,
  supportArticle,
  cancelSupportArticle,
  commentArticle,
  getArticle,
  getArticleById,
  getHotArticle,
  getRandomArticle,
} = require("../controller/article.controller");

// 1. 创建路由对象
const articleRouter = new KoaRouter({ prefix: "/article" });

// 2. 定义路由中的映射
// 发布文章
articleRouter.post("/releaseArticle", verifyAuth, releaseArticle);
// 收藏文章
articleRouter.post("/saveArticle", verifyAuth, saveArticle);
// 取消收藏
articleRouter.delete("/cancelSaveArticle", verifyAuth, cancelSaveArticle);
// 点赞文章
articleRouter.post("/supportArticle", verifyAuth, supportArticle);
// 取消点赞
articleRouter.delete("/cancelSupportArticle", verifyAuth, cancelSupportArticle);
// 评论文章
articleRouter.post("/commentArticle", verifyAuth, commentArticle);
// 获取文章
articleRouter.get("/getArticle", getArticle);
// 通过id获取文章
articleRouter.get("/getArticleById/:articleId", getArticleById);
// 获取热门文章
articleRouter.get("/getHotArticle", getHotArticle);
// 获取随机文章
articleRouter.get("/getRandomArticle", getRandomArticle);

module.exports = articleRouter;
